package com.jia.controller;

import com.jia.dto.admin.ActivityDto;
import com.jia.entity.Activity;
import com.jia.service.ActivityService;
import com.jia.vo.Result;
import com.jia.vo.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api")
public class AvrivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/avtivity/{page}/{limit}")
    @Operation(description = "获取活动列表")
    public Result<Activity> getActivityList(@PathVariable("page") Integer page,
                                            @PathVariable("limit") Integer limit,
                                            ActivityDto activityDto
                                            ) {
        return Result.build(activityService.findAll(page, limit, activityDto), ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getUpdateActivityState/{id}")
    @Operation(summary = "修改优惠券状态")
    public Result getUpdateActivityState(@PathVariable("id") int id) {
        activityService.updateState(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/getDeleteActivity/{id}")
    @Operation(summary = "删除优惠券")
    public Result getDeleteActivity(@PathVariable("id") int id) {
        activityService.removeById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/getAddActivity")
    @Operation(summary = "添加活动")
    public Result getAddActivity(@RequestBody Activity activity) {
        activity.setCreatetime(new Date());
        activity.setState(0);
        activityService.save(activity);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


}
